<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>登录</title>
</head>
<link rel="stylesheet" href="../src/css/public.css">
<link rel="stylesheet" href="../src/css/in.css">

<body>
    <header>
        <div class="center header-top">
            <span>一年逛两次 <img src="../static/img/logo.png" alt=""> 每次都有新选择！</span>
            <ul>
                <li class="my"></li>
                <li><a href="login.html" title="登录">登录</a></li>
                <li><a href="./register.html" title="注册账号">注册</a></li>
                <li><a href="../index.html" title="主页">主页</a></li>
                <li class="call"><a href="./call.html" title="call me">联系我们</a></li>
            </ul>
        </div>
    </header>
    <div class="login">
        <div class="logo-one"><a href="../index.html">
                <img src="../static/img/logo (4).png" alt="" title="super clothes"></a>
        </div>
        <h3>登录super clothes</h3>
        <form action="javascript:;">
            <table>
                <tr>
                    <td>账号：</td>
                    <td> <input type="text" name="username"></td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                </tr>
                <tr>
                    <td>密码：</td>
                    <td> <input type="password" name="password"></td>
                </tr>

                <tr>
                    <td></td>
                    <td> <input type="checkbox" name="remember"> <span class="orz">记住密码</span> </td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                </tr>
                <tr>
                    <td></td>
                    <td> <button>登录</button></td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                </tr>
                <tr>
                    <td></td>
                    <td>没有账号？ <a href="./register.html">去注册</a></td>
                </tr>
            </table>
        </form>
    </div>
    <footer>
        <p>北京超衣设计文化有限公司 京网文[2019]10010-8848号 京ICP备12008848号</p>
        <p>Copyright © Shifone 2019 - 2080 All rights reserved.</p>

    </footer>
</body>
<script src="../dist/js/jquery.min.js"></script>
<script src="../src/js/promiseAjax.js"></script>
<script src="../src/js/free.js"></script>
<script src="../src/js/public.js"></script>
<script type="text/javascript">
    document.querySelector("button").onclick = function () {
        var username = document.querySelector('input[name="username"]').value.trim();
        usernameReg = /^[0-9a-zA-Z\u4e00-\u9fa5]{6,16}$/;
        if (!usernameReg.test(username)) {
            alert("请正确填写用户名");
            return false;
        }
        var password = document.querySelector('input[name="password"]').value.trim();
        var passwordReg = /^\w{6,18}$/;
        if (!passwordReg.test(password)) {
            alert("请正确填写密码");
            return false;
        }

        var remember = document.querySelector("input[name='remember']").checked;

        PAjax({
            method: "post",
            url: "../api/login.php",
            data: {
                uname: username,
                pass: password,
            },
            async: true,
            success: function (res) {
                resolve(res);
            }
        }).then(function (res) {
            console.log(res)
            res = JSON.parse(res);
            if (res.status === 200) {
                setCookie('name', username, 1 * 60 * 60 * 24);
                if (remember) {
                    setCookie("pass", password, 7 * 24 * 60 * 60);
                } else {
                    delCookie("pass");
                }
                alert(res.msg);
                location.href = '../index.html';
            } else if (res.status === 400) {
                alert(res.msg);
                location.href = 'login.html';
            }
        });
    }
</script>

</html>